-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inputLength
to seek
and keyCount
to keypress
#308
base: master
Are you sure you want to change the base?
Conversation
The new argument `inputLength` (which defaults to 1) determines how many characters the `seek` command accepts. This uses the newly implemented `keyCount` argument (which also defaults to 1) to accept multiples keypresses. The most immediate use for this is to implement the equivalent of vim-sneak. Sneak accepts two key presses, and like `t`, sneak jumps the cursor right before the next match of the input. This also includes some shortcut commands for easily sneaking with the `s` key in normal mode using select.orSneak.
6420daa
to
05bfdd8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Sorry for taking that long to review, I've been really busy.
Also, please add a test (and preferably one for each selection mode)! A good location would be test/suite/commands/seek.md
.
src/api/prompt.ts
Outdated
*/ | ||
export async function keypress(context = Context.current): Promise<string> { | ||
export async function keypress(context = Context.current, keyCount: number = 1): Promise<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export async function keypress(context = Context.current, keyCount: number = 1): Promise<string> { | |
export async function keypress({ keyCount = 1 }: Readonly<{ keyCount: number }> = {}, context = Context.current): Promise<string> { |
By convention, context
should be the last parameter. In case newer parameters are added later, I think we should put keyCount
in an object as well.
src/commands/selections.ts
Outdated
@@ -351,6 +351,7 @@ export function filter( | |||
* | Title | Identifier | Keybinding | Command | | |||
* | -------------- | --------------- | --------------------- | ------------------------------------------------------------------------------------------------- | | |||
* | Leap or select | `select.orLeap` | `s` (kakoune: normal) | `[".ifEmpty", { then: [[".seek.leap", { ... }]], otherwise: [[".selections.select", { ... }]] }]` | | |||
* | Leap or select | `select.orSneak` | `s` (kakoune: normal) | `[".ifEmpty", { then: [[".seek", { inputLength: 2, ... }]], otherwise: [[".selections.select", { ... }]] }]` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | Leap or select | `select.orSneak` | `s` (kakoune: normal) | `[".ifEmpty", { then: [[".seek", { inputLength: 2, ... }]], otherwise: [[".selections.select", { ... }]] }]` | | |
* | Sneak or select | `select.orSneak` | `s` (kakoune: normal) | `[".ifEmpty", { then: [[".seek", { inputLength: 2, ... }]], otherwise: [[".selections.select", { ... }]] }]` | |
Also, s
conflicts with select.orLeap
above. For now I think we should keep it this way (and add no keybinding for select.orSneak
, then if users start to use .orSneak
more we can change the keybinding (which should be fine, since both of these bindings are experimental.
Also also, please re-format the whole table to take the longer identifier / title into account.
src/commands/selections.ts
Outdated
* | Title | Identifier | Keybinding | Command | | ||
* | ------------------------ | ----------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------- | | ||
* | Leap or select backward | `splitLines.orLeap.backward` | `a-s` (kakoune: normal) | `[".ifEmpty", { then: [[".seek.leap", { direction: -1, ... }]], otherwise: [[".selections.splitLines", { ... }]] }]` | | ||
* | Sneak or select backward | `splitLines.orSneak.backward` | `a-s` (kakoune: normal) | `[".ifEmpty", { then: [[".seek", { inputLength: 2, direction: -1, ... }]], otherwise: [[".selections.splitLines", { ... }]] }]` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | Sneak or select backward | `splitLines.orSneak.backward` | `a-s` (kakoune: normal) | `[".ifEmpty", { then: [[".seek", { inputLength: 2, direction: -1, ... }]], otherwise: [[".selections.splitLines", { ... }]] }]` | | |
* | Sneak or select backward | `splitLines.orSneak.backward` | | `[".ifEmpty", { then: [[".seek", { inputLength: 2, direction: -1, ... }]], otherwise: [[".selections.splitLines", { ... }]] }]` | |
src/commands/load-all.ts
Outdated
function getInputLength(argument: { inputLength?: number }) { | ||
const len = argument.inputLength || 1; | ||
if (len > 0 && Number.isInteger(len)) { | ||
return len; | ||
} | ||
throw new ArgumentError('"inputLength" must be positive integer'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not used.
src/commands/load-all.ts
Outdated
if (len > 0 && Number.isInteger(len)) { | ||
return len; | ||
} | ||
throw new ArgumentError('"inputLength" must be positive integer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new ArgumentError('"inputLength" must be positive integer'); | |
throw new ArgumentError('"inputLength" must be positive integer', "inputLength"); |
src/commands/load-all.ts
Outdated
@@ -30,6 +30,14 @@ function getRegister<F extends Register.Flags | Register.Flags[]>( | |||
return (argument.register = register as any); | |||
} | |||
|
|||
function getInputLength(argument: { inputLength?: number }) { | |||
const len = argument.inputLength || 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If argument.inputLength
is 0
, this will yield 1
. I think using the same logic as getCount
(using +
to cast to a number and then checking that len > 0 && Number.isInteger(len)
would be better (so if the input is a string for some reason, that still works).
Just wanted to leave an update here. I've responded to all of the minor comments at this point and am working through the tests. I love the test framework you're using by the way, super cool! In setting up / thinking through the tests I noticed a bug where the value of |
Brief update: I figured out the cause of my woes when dealing with counts for sneak commands (see #310). Having identified that as a separate issue I'm now moving on to finalizing the tests for this. |
Alright, tests are passing locally. I think this is ready for review again. |
Hey, just checking in on this. Are there any issues I need to address before you can review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! Sorry it took me so long to review this PR.
export async function keypress(context = Context.current): Promise<string> { | ||
export async function keypress(params: Readonly<{ keyCount?: number }>, | ||
context = Context.current): Promise<string> { | ||
const keyCount = params.keyCount || 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If params.keyCount
is 0
, this will evaluate to 1
. I'm not sure how I feel about that. IMO for params.keyCount === 0
we could return immediately with an empty string.
try { | ||
let keys = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I try to only put throwing stuff in try
, and to keep everything else out of it.
try { | |
let keys = ""; | |
let keys = ""; | |
try { |
function getInputLength(argument: { inputLength?: number }) { | ||
const len = +(argument.inputLength as any); | ||
if (len > 0 && Number.isInteger(len)) { | ||
return len; | ||
} | ||
throw new ArgumentError('"inputLength" must be positive integer', "inputLength"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this function is still unused?
You probably wanted to automatically use this function for inputLength
arguments, similarly to what's done with count
and repetitions
?
|
||
keys: | ||
qwerty: "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is a result of having an initial command and then removing it (the script that generates this file tries to keep old values to avoid throwing away manual changes). This should be removed (and ditto a bit lower in the file).
@@ -250,3 +250,50 @@ ghi | |||
jkl | |||
mno | |||
``` | |||
|
|||
# 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test when seeking backward? I don't know what the expected result is, but there might be some problems with the selection not extending exactly as expected.
No problem. Thanks for taking a look, I'll take a read through and update as needed. |
This enables both
seek
andkeypress
ux more generally to accept more than one keypress.The most immediate use for this is to implement the equivalent of vim-sneak. Sneak accepts two key presses, and like
t
, sneak jumps the cursor right before the next match of the input.This also includes some shortcut commands for easily sneaking with the
s
key in normal mode usingselect.orSneak
.Would close #305